OUT Statement ---------------------------------------------------------------------------- Action Sends a byte to a hardware I-O port. Syntax OUT port, data% Remarks The OUT statement complements the INP function, which returns the byte read from a hardware I-O port. The OUT statement uses the following arguments. ----------------------------------------------------------------------------- Argument Description Argument Description ---------------------------------------------------------------------------- port A numeric expression with an integer value between 0 and 65,535, inclusive, that identifies the destination hardware I-O port. data% A numeric expression with an integer value between 0 and 255, inclusive, that is the data to be sent to the port. The OUT statement and the INP function give a BASIC program direct control over the hardware in a system through the I-O ports. OUT and INP must be used carefully because they directly manipulate the system hardware. Note The OUT statement is not available in OS-2 protected mode. See Also INP, WAIT Example The following example uses the OUT and INP statements to control the timer and speaker to produce a note. ' Play a scale using speaker and timer. CONST WHOLE = 5000!, QRTR = WHOLE - 4! CONST C = 523!, D = 587.33, E = 659.26, F = 698.46, G = 783.99 CONST A = 880!, B = 987.77, C1 = 1046.5 CALL Sounds(C, QRTR). CALL Sounds(D, QRTR) CALL Sounds(E, QRTR). CALL Sounds(F, QRTR) CALL Sounds(G, QRTR). CALL Sounds(A, QRTR) CALL Sounds(B, QRTR). CALL Sounds(C1, WHOLE) SUB Sounds (Freq!, Length!) STATIC ' Ports 66, 67, and 97 control timer and speaker. ' Divide clock frequency by sound frequency ' to get number of "clicks" clock must produce. Clicks% = CINT(1193280! - Freq!) LoByte% = Clicks% AND &HFF HiByte% = Clicks% \ 256 OUT 67, 182' Tell timer that data is coming. OUT 66, LoByte%' Send count to timer. OUT 66, HiByte% SpkrOn% = INP(97) OR &H3' Turn speaker on by setting OUT 97, SpkrOn%' bits 0 and 1 of PPI chip. FOR I! = 1 TO Length!. NEXT I!' Leave speaker on. SpkrOff% = INP(97) AND &HFC ' Turn speaker off. OUT 97, SpkrOff% END SUB